/**
 * 
 */
package com.flashdeck.activity;

import com.flashdeck.Extras;
import com.flashdeck.R;
import com.flashdeck.dao.SettingsDao;
import com.flashdeck.dao.impl.SettingsDaoImpl;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

/**
 * @author Vincentas
 *
 */
public class SettingsActivity extends Activity {

	private static final int FOLDER_REQUEST_CODE = 1;
	
	private EditText decksLocationEditText;
	
	private EditText remoteRepositoryEditText;
	/* (non-Javadoc)
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.settings_layout);
		
		remoteRepositoryEditText = (EditText) findViewById(R.id.RemoteRepositoryEditText);
		remoteRepositoryEditText.setText(getSettingsDao().getRemoteRepository());
		
		decksLocationEditText = (EditText) findViewById(R.id.DecksLocationEditText);
		decksLocationEditText.setText(getSettingsDao().getDeckFolder().getAbsolutePath());
		decksLocationEditText.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(SettingsActivity.this, FileBrowserActivity.class);
				startActivityForResult(intent, FOLDER_REQUEST_CODE);
			}
		});		
	}

	/* (non-Javadoc)
	 * @see android.app.Activity#onActivityResult(int, int, android.content.Intent)
	 */
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (requestCode == FOLDER_REQUEST_CODE) {
			if (resultCode == RESULT_OK) {
				String decksLocation = data.getStringExtra(Extras.DECKS_LOCATION);
				decksLocationEditText.setText(decksLocation);
			}
		} else {
			super.onActivityResult(requestCode, resultCode, data);
		}
	}
	
	private SettingsDao getSettingsDao() {
		return SettingsDaoImpl.getInstance();
	}
	
	

	
}
